/**
 * Copyright 2007 Jason Horman, Pete Aykroyd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.functor.expression;

import org.functor.Functor;
import org.functor.UnaryPredicate;

import java.util.List;

/**
 * Compiles expressions into {@link UnaryPredicate predicates}.
 */
public class FunctorExpressionCompiler extends ExpressionCompiler<Functor, UnaryPredicate> {
	/**
	 * This allows an expression to compile itself. And expression implementing
	 * {@link SelfFunctorCompiling} will be able to compile itself. If there is a
	 * more specific visit method it will be called instead.
	 */
	public Functor visit(SelfFunctorCompiling selfCompiling) {
		return selfCompiling.compile();
	}

	/**
	 * Returns a UnaryPredicate.And.
	 */
	protected UnaryPredicate createAnd(List<UnaryPredicate> predicates) {
		return new UnaryPredicate.And(predicates);
	}

	/**
	 * Returns a UnaryPredicate.Or.
	 */
	protected UnaryPredicate createOr(List<UnaryPredicate> predicates) {
		return new UnaryPredicate.Or(predicates);
	}

	/**
	 * Returns a UnaryPredicate.Not.
	 */
	public UnaryPredicate createNot(UnaryPredicate predicate) {
		return UnaryPredicate.not(predicate);
	}

	/**
	 * Returns a UnaryPredicate.isTrue.
	 */
	public UnaryPredicate visit(True e) {
		return UnaryPredicate.isTrue();
	}

	/**
	 * Returns a UnaryPredicate.isFalse.
	 */
	public UnaryPredicate visit(False e) {
		return UnaryPredicate.isFalse();
	}
}
